import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:xvideos/assets_tool/app_colors.dart';
import 'package:xvideos/assets_tool/images.dart';
import 'package:xvideos/extension/date_string_extension.dart';
import 'package:xvideos/hj_model/mine/excharge/bill_page_model.dart';
import 'package:xvideos/hj_page/mine_business/make_money/withdraw_details_model.dart';
import 'package:xvideos/hj_utils/date_time_util.dart';
import 'package:xvideos/hj_utils/global.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';

class GoldRecordItem extends StatelessWidget {
  final BillItemModel model;

  const GoldRecordItem(this.model, {super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                12.sizeBoxH,
                Text(
                  model.tranType ?? '',
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w400),
                ),
                4.sizeBoxH,
                Text(
                  model.desc ?? '',
                  style: TextStyle(color: Colors.white.withOpacity(.5), fontSize: 12, fontWeight: FontWeight.w400),
                ),
                4.sizeBoxH,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      model.createdAt.utcTimeSToYMDHMSString() ?? '',
                      style: TextStyle(color: Colors.white.withOpacity(.5), fontSize: 12, fontWeight: FontWeight.w400),
                    ),
                    Text(
                      '${model.realCount()}${model.unit()}',
                      style: const TextStyle(color: Color(0xffE1351F), fontSize: 14, fontWeight: FontWeight.w400),
                    ),
                  ],
                ),
                12.sizeBoxH,
                1.line,
              ],
            ),
          ),
        ],
      ),
    );
  }
}

//充值记录
class RechargeRecordItem extends StatelessWidget {
  final ListBean model;

  const RechargeRecordItem(this.model, {super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(
            "${model.productName ?? ""}",
            style: TextStyle(
              color: Colors.white,
              fontSize: 14,
              fontWeight: FontWeight.w500,
            ),
          ),
          2.sizeBoxH,
          InkWell(
            onTap: () {
              ///复制到剪切板
              Clipboard.setData(ClipboardData(text: model.orderId ?? ''));
              showToast('复制成功');
            },
            child:  Row(
              children: [
                Flexible(
                  child: Text(
                    '账单编号' + ': ${model.orderId}',
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(fontSize: 14, color: Color(0xE5FFFFFF), fontWeight: FontWeight.w500),
                  ),
                ),
                2.sizeBoxW,
                Image.asset(
                  'icon_copy.png'.mineImgPath,
                  width: 24,
                ),
              ],
            ),
          ),
          2.sizeBoxH,
          Text(
            "状态: ${getStatus(model.status ?? 0)}",
            style: TextStyle(
              color: Color(0xffE1351F),
              fontSize: 12,
            ),
          ),
          2.sizeBoxH,
          Text(
            model.createdAt?.utcTimeSToYMDString() ?? "",
            style: TextStyle(fontSize: 12, color: Color(0xff525252)),
          ),
          12.sizeBoxH,
          0.5.line,
        ],
      ),
    );
  }

  ///支付状态
  String getStatus(int status) {
    switch (status) {
      case 1:
        return "进行中";
      case 2:
        return "购买失败";
      case 3:
        return "购买成功";
    }
    return "未知";
  }

  Color getStatusColor(int status) {
    var statusStr = Color(0xffffd382);
    switch (status) {
      case 2:
        statusStr = Color(0xffFF1060);
        break;
      case 3:
        statusStr = Color(0xff28C445);
        break;
    }

    return statusStr;
  }
}

class InComeRecordItem extends StatelessWidget {
  final IncomeModel model;
  const InComeRecordItem(this.model, {super.key});

  @override
  Widget build(BuildContext context) {
    return Container(  
        child: Column(children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text(
                      "${model.tranType}",
                      style: const TextStyle(color: Color(0xFFEFEFEF), fontWeight: FontWeight.w500, fontSize: 14.0),
                    ),
                    Container(
                      margin: EdgeInsets.symmetric(vertical: 4),
                      child: Text(
                        model.desc ?? "",
                        style: TextStyle(fontSize: 12, color: Colors.white60),
                      ),
                    ),
                    Text(
                  DateTimeUtil.utc2iso(model.createdAt ?? ''),
                  style: const TextStyle(color: Color(0xFF525252), fontWeight: FontWeight.w400, fontSize: 12.0),
                ), 
                    12.sizeBoxH,
                  ],
                ),
              ), 
              12.sizeBoxW,
              Text(model.tranTypeInt == 111 ? "+${model.actualAmount}次" : "+${model.actualAmount}金币",
              style: const TextStyle(color: const Color(0xFFE1351F), fontWeight: FontWeight.w400, fontSize: 12.0),
              textAlign: TextAlign.left)
            ],
          ),
          0.5.line,
        ]));
  }
}

//提现明细cell
class WithdrawalRecordItem extends StatefulWidget {
  final ListBean model;
  const WithdrawalRecordItem(this.model, {super.key});

  @override
  State<WithdrawalRecordItem> createState() => _WithdrawalRecordItemState();
}

class _WithdrawalRecordItemState extends State<WithdrawalRecordItem> {
  ListBean get model => widget.model;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 4),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          12.sizeBoxH,
          Text(
            '${(model.money ?? 0) ~/ 100}元',
            style: TextStyle(fontSize: 14, color: AppColors.primaryXColor, fontWeight: FontWeight.w500),
          ),
          6.sizeBoxH,
          Row(
            children: [
              Expanded(
                child: Text(
                  '账单编号' + ': ${model.id}',
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(fontSize: 14, color: Color(0xE5FFFFFF), fontWeight: FontWeight.w500),
                ),
              ), 
              InkWell(
                onTap: () {
                  ///复制到剪切板
                  Clipboard.setData(ClipboardData(text: model.id ?? ''));
                  showToast('复制成功');
                },
                child: Image.asset(
                  'mine_copy.png'.mineImgPath,
                  width: 24,
                ),
              )
            ],
          ),
          8.sizeBoxH,
          Text(
            '${getPayType(model.payType ?? "")}${getStatus(model.status ?? 0)}',
            style: TextStyle(fontSize: 12, color: getStatusColor()),
          ),
          6.sizeBoxH,
          Row(
            children: [
              Text(
                DateTimeUtil.utc2iso(model.createdAt ?? ''),
                style: TextStyle(fontSize: 12, color: Color(0x8CFFFFFF)),
              ),
              Spacer(),
              if (model.status != 5 && model.status != 1) ...[
                InkWell(
                  onTap: () => setState(() {
                    model.showReason = !model.showReason;
                  }),
                  child: Text(
                    '查看原因',
                    style: TextStyle(fontSize: 12, color: AppColors.primaryXColor),
                  ),
                )
              ],
            ],
          ),
          if (model.showReason) ...[
            12.sizeBoxH,
            Text(
              '${model.statusDesc}',
              style: TextStyle(fontSize: 12, color: Colors.white),
            ),
          ],
          12.sizeBoxH,
          0.5.line,
        ],
      ),
    );
  }

  String getPayType(String payType) {
    if (payType.endsWith("alipay")) {
      return "支付宝";
    } else if (payType.endsWith("usdt")) {
      return "USDT";
    } else {
      return "银行卡";
    }
  }

  ///支付状态
  String getStatus(int status) {
    switch (status) {
      case 1:
        return '提现审核中';
      case 2:
        return '审核通过，转账中';
      case 3:
        return '提现已拒绝';
      case 4:
        return '未知错误';
      case 5:
        return '提现成功';
      case 6:
        return '提现失败';
    }
    return '';
  }

  ///支付状态
  Color getStatusColor() {
    if (model.status == 5) {
      return Color(0xff0360FC);
    } else {
      return Color(0x8CFFFFFF);
    }
  }
}
